if __name__ == '__main__':
    import argparse
    import os
    import random

    from PIL import Image

    parser = argparse.ArgumentParser(description='show random patches of 8*4 grid')
    parser.add_argument('base_dir', default=None, metavar='BASE_DIR', type=str,
                        help='Path to the config file in json format')
    args = parser.parse_args()

    with open(os.path.join(args.base_dir, "normal.list")) as f:
        normal = [line.strip() for line in f]
    with open(os.path.join(args.base_dir, "tumor.list")) as f:
        tumor = [line.strip() for line in f]

    _UNIT_SIZE = 225
    target = Image.new('RGB', (_UNIT_SIZE * 8, _UNIT_SIZE * 4))

    for row in [0,1]:
        for i, path in random.sample(normal, 8):
            im = Image.open(os.path.join(args.base_dir, path))
            target.paste(im, (i * _UNIT_SIZE, row * _UNIT_SIZE))

    for row in [2,3]:
        for i, path in random.sample(tumor, 8):
            im = Image.open(os.path.join(args.base_dir, path))
            target.paste(im, (i * _UNIT_SIZE, row * _UNIT_SIZE + 10))

    target.show()